import { _decorator, Component, director, EventKeyboard, Input, input } from 'cc'
import { AimDirection } from '../actor/AimDirection'
import { GameEvent } from '../event/gameEvent'
const { ccclass, property } = _decorator

@ccclass('UIInput')
export class UIInput extends Component {

    start() {
        input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this)
    }
    onKeyDown(e: EventKeyboard) {

        switch (e.keyCode) {
            case 39:
                this.onFileRight()
                break
            case 37:
                this.onFileLeft()
                break
            case 38:
                this.onFireTop()
                break
            case 40:
                this.onFileDown()
                break



            default:
                break
        }

    }
    update(deltaTime: number) {


    }
    onFireTop() {
        director.emit(GameEvent.OnFireButtonClicked, AimDirection.Up)
    }
    onFileDown() {
        director.emit(GameEvent.OnFireButtonClicked, AimDirection.Down)
    }
    onFileLeft() {
        director.emit(GameEvent.OnFireButtonClicked, AimDirection.Left)
    }
    onFileRight() {
        director.emit(GameEvent.OnFireButtonClicked, AimDirection.Right)
    }

}

